Chapter {seq chapter} {seq chapter readword} Word Processor File Format{tc "{seq chapter readword} Word Processor File Format"} This document describes the structure of a Psion word processor document file. The description to a level that allows other software to read and write non-password-protected document files. Psion word processor document files contain a file header, followed by a number of type-length-value records, from the following list: • options data • printer-related data • printer model data • page header • page footer • style data • emphasis data • document text • document index Document files created by the word processor will contain records in the order listed above. Each record consists of: • a two-byte record type • a two-byte record length, len • len bytes of data Unless stated otherwise, all dimensions are stored in twips (1/1440 inch). Reserved locations All locations reserved for future use contain a value of zero. The document header{tc "The document header" \l 2} The document header is 40 bytes long. It starts with the 16-byte zero terminated file signature "PSIONWPDATAFILE" followed by a two byte file version number. Following this is a 20-byte struct, containing password data. For a non-password-protected document there are two bytes of zero followed by eighteen bytes, each containing 0xEA. The remaining two bytes of the header are reserved for future use. Record types{tc "Record types" \l 2} The options data record (type 1, length 10){tc "The options data record (type 1, length 10)" \l 3} The options data record contains the following items: UWORD cpos saved cursor position UBYTE symbols show screen symbols UBYTE backup TRUE to keep backups (this item is used on the MC only: it is not used on Series3 machines) UBYTE statzoom top four bits indicate the current zoom state (0x22 by default), lowest four bits indicate the status window size: 0, 1 or 2 for off, small or big respectively (this item is used by the Series3a only) UBYTE style TRUE to show style bar UBYTE mono TRUE to load text by line, else by paragraph UBYTE outlevel lowest outline level to display UBYTE spare1 reserved for future use UWORD spare2 reserved for future use Displayed screen symbols are determined by any combination of the following bit fields in symbols: 0x01 0x02 0x04 0x08 0x10 show tabs show spaces show paragraph end markers show hyphens show forced line breaks Printer-related data record (type 2, length 58){tc "Printer-related data record (type 2, length 58)" \l 3} This record contains information required to format the document for the printer and to control the printing process. It includes, amongst other items, descriptions of the page size and margins, the page numbering style, header and footer position and alignment. This record consists of a structure that is used to control the display and WDR printing of formatted text in all applications that require such services. It therefore contains some fields that are not relevant to the word processor. The following description is in terms of the P_EXTENT, SCRLAY_FONT and PAGES_HEADER structs, defined as: typedef struct { WORD x; WORD y; } P_POINT; typedef struct { P_POINT tl; WORD width; WORD height; } P_EXTENT; typedef struct { UWORD fid; /* typeface number */ (1) UWORD style; /* font style */ (2) UWORD height; /* height of font in twips */ } SCRLAY_FONT; typedef struct { SCRLAY_FONT f; /* font data */ UBYTE align; /* header alignment */ (3) UBYTE first_page; /* TRUE to emit on first page */ } PAGES_HEADER; In these terms, the content of the printer-related record is: PAGE DATA WORD width WORD height P_EXTENT body WORD hdtop WORD hdbot WORD pdrflags WORD docflags UWORD pgbeg UWORD pgend page width page height body print region, with respect to top left of page (4) page header position (5) page footer position (6) 0 for portrait, 1 for landscape always 3 for word processor page number to start printing (first page is 1) last page number to print (7) RUNNING PAGE HEADERS PAGES_HEADER top PAGES_HEADER bot page header page footer PAGE NUMBERING WORD offset WORD last WORD style page numbering offset page count, for %m (always reset by pagination) page number style (8) MISCELLANEOUS SCRLAY_FONT f UBYTE size_choice UBYTE wo_control UWORD spare1 UWORD spare2 base font for body print region (9) paper size index (10) TRUE to disable widow and orphan control reserved for future use reserved for future use Notes (1) Typeface numbers are defined in the following list: 0 COURIER 1 PICA 2 ELITE 3 PRESTIGE 4 LETTER_GOTHIC 5 GOTHIC 6 CUBIC 7 LINEPRINTER 8 HELVETICA 9 AVANT_GARDE 10 SPARTAN 11 METRO 12 PRESENTATION 13 APL 14 OCR_A 15 OCR_B 16 STANDARD_ROMAN 17 EMPEROR 18 MADELEINE 19 ZAPF_HUMANIST 20 CLASSIC 21 OPTIONAL_SA 22 OPTIONAL_SB 23 OPTIONAL_SC 24 TIMES_ROMAN 25 CENTURY 26 PALATINO 27 SOUVENIR 28 GARAMOND 29 CALEDONIA 30 BODONI 31 UNIVERSITY 32 SCRIPT 33 SCRIPT_PS 34 OPTIONAL_SCA 35 OPTIONAL_SCB 36 COMMERCIAL_SCRIPT 37 PARK_AVENUE 38 CORONET 39 OPTIONAL_SCC 40 GREEK 41 KANA 42 HEBREW 43 OPTIONAL_A 44 RUSSIAN 45 OPTIONAL_B 46 OPTIONAL_C 47 OPTIONAL_D 48 NARRATOR 49 EMPHASIS 50 ZAPF_CHANCERY 51 OPTIONAL_DA 52 OLD_ENGLISH 53 OPTIONAL_DB 54 OPTIONAL_DC 55 COOPER_BLACK 56 SYMBOL 57 LINE_DRAW 58 MATH_7 59 MATH_8 60 DINGBATS 61 EAN 62 PC_LINE 63 OPTIONAL_SYA A typeface that is not supported by the current printer will be mapped to a supported typeface. (2) The font style may be zero, or any sensible combination of the following attributes: 0x01 0x02 0x04 0x08 0x10 underline bold italic superscript subscript Styles or style combinations that are not supported by the current printer are ignored. (3) The running page header alignment may be any one of: 0 1 2 4 5 left aligned right aligned centred 2-column 3-column (4) In terms of the body struct and the page width and height, the page margins are: left top right bottom body.tl.x body.tl.y width-body.tl.x-body.width height-body.tl.y-body.height (5) The page header position measures the vertical distance between the bottom of the header text and the top edge of the page body print region. (6) The page footer position measures the vertical distance between the bottom of the footer text and the bottom edge of the page body print region. (7) To print all pages, the last page number should be set to 0xffff. (8) The page number style is one of: 0 1 2 Arabic Roman, upper case Roman, lower case. (9) The body area base font data is not used by word processor documents. It should always specify the default font, with font number 0 (Courier) a style of 0 (normal) and a size of 240 (12 points). (10) The page size choice should correspond with the earlier page width and height. The following (English) page sizes are recognised: Choice Page type Width Height 0 A4 11906 16838 1 Custom - - 2 Executive 10440 15120 3 Legal 12240 20160 4 Letter 12240 15840 5 Monarch 5580 10800 6 DL 6236 12472 Note that items 2 to 6 may be different in non-English versions of the software. Printer model data record (type 3, variable length){tc "Printer model data record (type 3, variable length)" \l 3} The record consists of a zero terminated string, containing the full path name of the current printer driver file, preceded by a one byte index to the printer model within the file. The default value is: 0 "ROM::\BJ.WDR" Page header record (type 4, variable length){tc "Page header record (type 4, variable length)" \l 3} The record contains the page header text as a zero terminated string. The string may not exceed 80 bytes. Page footer record (type 5, variable length){tc "Page footer record (type 5, variable length)" \l 3} The record contains the page footer text as a zero terminated string. The string may not exceed 80 bytes. Style data record (type 6, length 80){tc "Style data record (type 6, length 80)" \l 3} The file may contain up to 64 such records, each of which defines a single style. The following description is in terms of the SCRLAY_FONT struct (described above) and the SCRLAY_MARGINS, SCRLAY_SPACING and SCRLAY_TABSTOP structs, defined as: typedef struct { UWORD left; /* left margin */ (1) UWORD right; /* right margin */ UWORD indent; /* left margin for first line of a paragraph */ UWORD align; /* alignment */ (2) } SCRLAY_MARGINS; typedef struct { UWORD line; /* space between lines in a paragraph */ UWORD above; /* space above paragraph */ UWORD below; /* space below paragraph */ UWORD flags; /* keep together/next and new page */ (3) } SCRLAY_SPACING; typedef struct { UWORD x; /* tab position */ UWORD type; /* tab type */ (4) } SCRLAY_TABSTOP; In these terms, the content of the style data record is: TEXT sc[2] TEXT tag[16] UWORD sflags SCRLAY_FONT f UWORD inherit SCRLAY_MARGINS marg SCRLAY_SPACING spc UWORD olevel UWORD ntabs SCRLAY_TABSTOP tab[8] two-letter short code style tag name style control flags (5) paragraph base font (6) inherited attributes (7) margin positions paragraph vertical spacing outliner level number of tabstops in following table up to 8 tabstops, in ascending position order Notes (1) Paragraph margins are relative to the page margins (the left and right edges of the body print region). (2) The paragraph alignment may be one of: 0 1 2 3 left aligned right aligned centred justified (3) The spacing flags may be any combination of: 0x01 0x02 0x04 keep on same page as following paragraph keep whole paragraph on one page paragraph starts a new page (4) The tab type may be any one of the following: 0 1 2 left tab right tab centred tab (5) The style control flags may contain any combination of: 0x02 0x04 undeletable default There must be one default style and at least one undeletable style in every document (in all Psion documents they are the same - style BT). It does not make sense for the default style to be deletable. (6) In addition to the typeface numbers listed earlier, a typeface number of -1 is used to signify that the typeface and font size are to be inherited from the default style. In such a case the font size is conventionally set to zero. (7) The inherited attributes field may contain any combination of: 0x01 0x02 0x04 underline bold italic For each bit that is set, the corresponding bit in the style field of the SCRLAY_FONT struct must be clear. Inherited attributes are taken from the default style. Emphasis data record (type 7, length 28){tc "Emphasis data record (type 7, length 28)" \l 3} The file may contain up to 16 such records, each of which defines a single emphasis. The following description is in terms of the SCRLAY_FONT struct (described above). In these terms, the content of the emphasis data record is: TEXT sc[2] TEXT tag[16] UWORD sflags SCRLAY_FONT f UWORD inherit two-letter short code emphasis tag name emphasis control flags (1) emphasis font (2) inherited attributes (3) Notes (1) The emphasis control flags must contain the value 0x01, together with any combination of: 0x02 0x04 undeletable default There must be one default emphasis and at least one undeletable emphasis in every document (in all Psion documents they are the same - emphasis NN). It does not make sense for the default emphasis to be deletable. (2) In addition to the typeface numbers listed earlier, a typeface number of -1 is used to signify that the typeface and font size are to be inherited from the enclosing paragraph style (which may itself inherit from the default style). In such a case the font size is conventionally set to zero. (3) The inherited attributes field may contain any sensible combination of: 0x01 0x02 0x04 0x08 0x10 underline bold italic superscript subscript For each bit that is set, the corresponding bit in the style field of the SCRLAY_FONT struct must be clear. Inherited attributes are taken from the enclosing paragraph style (which may itself inherit from the default style). Document text record (type 8, variable length){tc "Document text record (type 8, variable length)" \l 3} This record contains the entire text of the document. Each paragraph, except for the final one, is terminated by a zero. The content conforms with the IBM Code Page 850 symbol set, together with the following additional symbols: HARD_HYPHEN 7 SOFT_HYPHEN 14 HARD_SPACE 15 unbreakable hyphen, not a word delimiter optional, or potential, hyphen unbreakable space, not a word delimiter Document index record (type 9, variable length){tc "Document index record (type 9, variable length)" \l 3} This record contains a number of six byte entries which are used to apply style and emphasis to the document text. Each entry consists of: • a length (word) • the two character short code of a style • the two character short code of an emphasis The entries conform to the following rules: • the sum of their lengths is one more than the length of the document text record (i.e. the document size, including the final paragraph terminator). • there is at least one entry per paragraph • the final entry for each paragraph includes the zero that terminates the paragraph • the short codes must correspond with styles and emphases contained in the earlier style data and emphasis data records Additional system information {seq chapter readword} Word Processor File Format {page|1} {page|1} {page|1}